package remote_work.client;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.custom.SashForm;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

import remote_work.dto.InputObject;
import remote_work.dto.OutputObject;
import remote_work.util.RequestService;

import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Text;

import com.ibm.icu.text.SimpleDateFormat;

/**
 * @author LiuPing
 *
 * 2018年3月13日
 */
public class MainUI {
	
	public static Shell shell;
	private Table table_usable;
	private Table table_submitted;
	private static  InputObject inputObject = new InputObject();
	private static OutputObject outputObject = null;
	private Table uploadFileTable;
	private static Map<String, Object> param = new HashMap<>();
	private static Map<String, Object> userInfo = new HashMap<>();
	private Text text_dept;
	private Text text_major;
	private Text text_course;
	private Table table_dept;
	private Table table_major;
	private Table table_course;
	private Text text_class;
	private Table table_class;
	Table table_downloaded;
	
	private MessageBox mb;
	private static Table table_checkable;
	private Text text_message;
	private Table table_message;
	
	Combo combo_course_teacher;
	Combo combo_class_teacher;
	
	public static void setParam(Map<String, Object> param) {
		MainUI.param = param;
	}
	
	public static void setUser(Map<String, Object> userInfo) {
		MainUI.userInfo = userInfo;
	}
	
	public static Map<String, Object> getUser() {
		return userInfo;
	}

	/**
	 * Launch the application.
	 * @param args
	 */
	private static MainUI window =null;
	public static void main(String[] args) {
		try {
			 window = new MainUI();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void successMessage(){
		inputObject = new InputObject();
		inputObject.addParams("state", "已提交");
		inputObject.setMethod("getFiles");
		outputObject = RequestService.execute(inputObject);
		List<Map<String, Object>> beans = outputObject.getBeans();
		if (beans.size() <= 0) {
			return;
		}
		table_checkable.removeAll();
		for (Map<String, Object> map : beans) {
			System.out.println(map.toString());
			TableItem item = new TableItem(table_checkable, SWT.NONE);
			item.setText(new String[] {(String) map.get("fileid"),(String) map.get("username"), (String) map.get("filename"), (String) map.get("uploaddate"), (String) map.get("state"),(String) map.get("score")});
		}
	}
	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		mb = new MessageBox(shell);
		shell.setSize(1366, 768);
		shell.setText("远程作业处理系统");
		shell.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Composite composite = new Composite(shell, SWT.NONE);
		composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm = new SashForm(composite, SWT.NONE);
		
		Composite composite_menu = new Composite(sashForm, SWT.NONE);
		composite_menu.setLayout(new GridLayout(4, false));
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		
		Label label_5 = new Label(composite_menu, SWT.NONE);
		label_5.setText("编号：");
		new Label(composite_menu, SWT.NONE);
		
		Label lblNewLabel = new Label(composite_menu, SWT.NONE);
		lblNewLabel.setText((String) userInfo.get("userid"));
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		
		Label label_6 = new Label(composite_menu, SWT.NONE);
		label_6.setText("系别：");
		new Label(composite_menu, SWT.NONE);
		
		Label label_7 = new Label(composite_menu, SWT.NONE);
		label_7.setText((String) userInfo.get("dept"));
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		
		Label label_8 = new Label(composite_menu, SWT.NONE);
		label_8.setText("专业：");
		new Label(composite_menu, SWT.NONE);
		
		Label label_9 = new Label(composite_menu, SWT.NONE);
		label_9.setText((String) userInfo.get("major"));
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		
		Label label_10 = new Label(composite_menu, SWT.NONE);
		label_10.setText("年级：");
		new Label(composite_menu, SWT.NONE);
		
		Label label_11 = new Label(composite_menu, SWT.NONE);
		label_11.setText((String) userInfo.get("grade"));
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		
		Label label_12 = new Label(composite_menu, SWT.NONE);
		label_12.setText("班级：");
		new Label(composite_menu, SWT.NONE);
		
		Label label_13 = new Label(composite_menu, SWT.NONE);
		label_13.setText((String) userInfo.get("clazz"));
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		new Label(composite_menu, SWT.NONE);
		
		Label label_14 = new Label(composite_menu, SWT.NONE);
		label_14.setText("角色：");
		new Label(composite_menu, SWT.NONE);
		
		Label label_15 = new Label(composite_menu, SWT.NONE);
		label_15.setText((String) userInfo.get("roleinfo"));
		
		Composite composite_content = new Composite(sashForm, SWT.NONE);
		composite_content.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(composite_content, SWT.NONE);
		
		
		
		TabItem tabItem_student = new TabItem(tabFolder, SWT.NONE);
		tabItem_student.setText("学生界面");
		
		Composite composite_2 = new Composite(tabFolder, SWT.NONE);
		tabItem_student.setControl(composite_2);
		composite_2.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_1 = new SashForm(composite_2, SWT.VERTICAL);
		
		Composite composite_4 = new Composite(sashForm_1, SWT.NONE);
		composite_4.setLayout(new GridLayout(32, false));
		
		Button button_download = new Button(composite_4, SWT.NONE);
		button_download.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		button_download.setText("下载作业");
		
		Button button_submit = new Button(composite_4, SWT.NONE);
		button_submit.setText("提交作业");
		
		Button button = new Button(composite_4, SWT.NONE);
		button.setText("刷新作业列表");
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		new Label(composite_4, SWT.NONE);
		
		
		
		
		Composite composite_1 = new Composite(sashForm_1, SWT.NONE);
		composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_3 = new SashForm(composite_1, SWT.NONE);
		
		Composite composite_5 = new Composite(sashForm_3, SWT.NONE);
		composite_5.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_usable = new Table(composite_5, SWT.BORDER | SWT.FULL_SELECTION);
		table_usable.setHeaderVisible(true);
		table_usable.setLinesVisible(true);
		
		TableColumn tableColumn_1 = new TableColumn(table_usable, SWT.NONE);
		tableColumn_1.setWidth(161);
		tableColumn_1.setText("可下载的作业");
		
		TableColumn tableColumn_17 = new TableColumn(table_usable, SWT.NONE);
		tableColumn_17.setWidth(115);
		tableColumn_17.setText("作业完成时间");
		
		TableColumn tableColumn_20 = new TableColumn(table_usable, SWT.NONE);
		tableColumn_20.setWidth(100);
		tableColumn_20.setText("课程");
		
		Composite composite_6 = new Composite(sashForm_3, SWT.NONE);
		composite_6.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_downloaded = new Table(composite_6, SWT.BORDER | SWT.FULL_SELECTION);
		table_downloaded.setHeaderVisible(true);
		table_downloaded.setLinesVisible(true);
		
		TableColumn tblclmnNewColumn = new TableColumn(table_downloaded, SWT.NONE);
		tblclmnNewColumn.setWidth(156);
		tblclmnNewColumn.setText("作业操作记录");
		
		TableColumn tableColumn_18 = new TableColumn(table_downloaded, SWT.NONE);
		tableColumn_18.setWidth(167);
		tableColumn_18.setText("操作时间");
		
		Composite composite_8 = new Composite(sashForm_3, SWT.NONE);
		composite_8.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_submitted = new Table(composite_8, SWT.BORDER | SWT.FULL_SELECTION);
		table_submitted.setHeaderVisible(true);
		table_submitted.setLinesVisible(true);
		
		TableColumn tableColumn_7 = new TableColumn(table_submitted, SWT.NONE);
		tableColumn_7.setWidth(152);
		tableColumn_7.setText("已提交的作业");
		
		TableColumn tableColumn_19 = new TableColumn(table_submitted, SWT.NONE);
		tableColumn_19.setWidth(137);
		tableColumn_19.setText("提交时间");
		
		TableColumn tableColumn_23= new TableColumn(table_submitted, SWT.NONE);
		tableColumn_23.setWidth(137);
		tableColumn_23.setText("作业状态");
		
		TableColumn tableColumn_21 = new TableColumn(table_submitted, SWT.NONE);
		tableColumn_21.setWidth(100);
		tableColumn_21.setText("成绩");
		sashForm_3.setWeights(new int[] {234, 229, 237});
		sashForm_1.setWeights(new int[] {46, 650});
		
		Button button_3 = new Button(composite_4, SWT.NONE);
		button_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		button_3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_submitted.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择要打开的文件");
					mb.open();
					return;
				}
				String fileName = table_submitted.getItem(selectionIndex).getText(0);
				inputObject = new InputObject();
				inputObject.addParams("fileName", fileName);
				inputObject.setMethod("downloadFile");
				outputObject = RequestService.execute(inputObject);
				if ("0".equals(outputObject.getReturnCode())) {
					String filePath = (String) outputObject.getBean().get("filePath");
					try {
						Runtime.getRuntime().exec("cmd /c start "+filePath);
						
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			}
		});
		button_3.setText("打开作业");
		Composite composite_3 = new Composite(tabFolder, SWT.NONE);
		
			TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
			tabItem.setText("教师界面");
			tabItem.setControl(composite_3);
			
		
		composite_3.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_4 = new SashForm(composite_3, SWT.NONE);
		
		Composite composite_12 = new Composite(sashForm_4, SWT.NONE);
		composite_12.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_5 = new SashForm(composite_12, SWT.VERTICAL);
		
		Composite composite_15 = new Composite(sashForm_5, SWT.NONE);
		composite_15.setLayout(new GridLayout(4, false));
		
		Button button_upload = new Button(composite_15, SWT.NONE);
		button_upload.setText("添加作业");
		
		Button button_deleteAssign = new Button(composite_15, SWT.NONE);
		button_deleteAssign.setText("删除作业");
		
		Label label_22 = new Label(composite_15, SWT.NONE);
		label_22.setText("选择班级：");
		
		combo_class_teacher = new Combo(composite_15, SWT.NONE);
		
		Composite composite_14 = new Composite(sashForm_5, SWT.NONE);
		composite_14.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		uploadFileTable = new Table(composite_14, SWT.BORDER | SWT.FULL_SELECTION);
		uploadFileTable.setLinesVisible(true);
		uploadFileTable.setHeaderVisible(true);
		
		TableColumn tblclmnid = new TableColumn(uploadFileTable, SWT.NONE);
		tblclmnid.setWidth(72);
		tblclmnid.setText("作业ID");
		
		TableColumn tableColumn_11 = new TableColumn(uploadFileTable, SWT.NONE);
		tableColumn_11.setWidth(100);
		tableColumn_11.setText("作业文件名");
		
		TableColumn tableColumn_10 = new TableColumn(uploadFileTable, SWT.NONE);
		tableColumn_10.setWidth(122);
		tableColumn_10.setText("上传日期");
		
		TableColumn tableColumn_12 = new TableColumn(uploadFileTable, SWT.NONE);
		tableColumn_12.setWidth(157);
		tableColumn_12.setText("有效期");
		sashForm_5.setWeights(new int[] {40, 645});
		
		Composite composite_9 = new Composite(sashForm_4, SWT.NONE);
		composite_9.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_6 = new SashForm(composite_9, SWT.VERTICAL);
		
		Composite composite_16 = new Composite(sashForm_6, SWT.NONE);
		composite_16.setLayout(new GridLayout(5, false));
		
		Label label_24 = new Label(composite_16, SWT.NONE);
		label_24.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_24.setText("选择课程：");
		
		combo_course_teacher = new Combo(composite_16, SWT.NONE);
		combo_course_teacher.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button button_querySubmit = new Button(composite_16, SWT.NONE);
		button_querySubmit.setText("查看学生提交作业");
		
		Button button_2 = new Button(composite_16, SWT.NONE);
		button_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_checkable.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择要打开的文件");
					mb.open();
					return;
				}
				String fileName = table_checkable.getItem(selectionIndex).getText(1);
				inputObject = new InputObject();
				inputObject.addParams("fileName", fileName);
				inputObject.setMethod("downloadFile");
				outputObject = RequestService.execute(inputObject);
				if ("0".equals(outputObject.getReturnCode())) {
					String filePath = (String) outputObject.getBean().get("filePath");
					try {
						Runtime.getRuntime().exec("cmd /c start "+filePath);
						
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}
			}
		});
		button_2.setText("打开文件");
		
		Button button_1 = new Button(composite_16, SWT.NONE);
		button_1.setText("打分");
		
		button_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("打分");
				int selectionIndex = table_checkable.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择要打分的作业");
					mb.open();
					return;
				}
				//System.out.println(table_checkable.getItem(selectionIndex).getText(0));
				inputObject = new InputObject();
				inputObject.addParams("fileId", table_checkable.getItem(selectionIndex).getText(0));
				inputObject.addParams("username", table_checkable.getItem(selectionIndex).getText(1));
				inputObject.addParams("filename", table_checkable.getItem(selectionIndex).getText(2));
				UpdateScore window = new UpdateScore();
				window.setInputObject(inputObject);
				window.open();
				/*String fileName = table_checkable.getItem(selectionIndex).getText(1);
				inputObject.addParams("fileName", fileName);
				inputObject.setMethod("downloadFile");
				outputObject = RequestService.execute(inputObject);
				if ("0".equals(outputObject.getReturnCode())) {
					String filePath = (String) outputObject.getBean().get("filePath");
					try {
						Runtime.getRuntime().exec("cmd /c start "+filePath);
						
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				}*/
			}
		});
		
		Composite composite_17 = new Composite(sashForm_6, SWT.NONE);
		composite_17.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_checkable = new Table(composite_17, SWT.BORDER | SWT.FULL_SELECTION);
		table_checkable.setHeaderVisible(true);
		table_checkable.setLinesVisible(true);
		
		TableColumn tableColumn_25 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_25.setWidth(0);
		//tableColumn_13.setText("学生");
		
		TableColumn tableColumn_13 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_13.setWidth(100);
		tableColumn_13.setText("学生");
		
		TableColumn tableColumn_14 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_14.setWidth(131);
		tableColumn_14.setText("作业文件名");
		
		TableColumn tableColumn_15 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_15.setWidth(124);
		tableColumn_15.setText("提交日期");
		
		TableColumn tableColumn_16 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_16.setWidth(59);
		tableColumn_16.setText("状态");
		
		TableColumn tableColumn_22 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_22.setWidth(79);
		tableColumn_22.setText("评分");
		
		TableColumn tableColumn_26 = new TableColumn(table_checkable, SWT.NONE);
		tableColumn_26.setWidth(100);
		tableColumn_26.setText("所属课程");
		sashForm_6.setWeights(new int[] {40, 645});
		sashForm_4.setWeights(new int[] {460, 636});
		
		TabItem tabItem_admin = new TabItem(tabFolder, 0);
		tabItem_admin.setText("管理员界面");
		
		Composite composite_18 = new Composite(tabFolder, SWT.NONE);
		tabItem_admin.setControl(composite_18);
		composite_18.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_7 = new SashForm(composite_18, SWT.NONE);
		
		Composite composite_19 = new Composite(sashForm_7, SWT.NONE);
		composite_19.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_8 = new SashForm(composite_19, SWT.VERTICAL);
		
		Composite composite_23 = new Composite(sashForm_8, SWT.NONE);
		composite_23.setLayout(new GridLayout(4, false));
		
		Label label_17 = new Label(composite_23, SWT.NONE);
		label_17.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_17.setText("系别名称：");
		
		text_dept = new Text(composite_23, SWT.BORDER);
		text_dept.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button button_addDept = new Button(composite_23, SWT.NONE);
		button_addDept.setText("添加");
		
		Button button_4 = new Button(composite_23, SWT.NONE);
		
		button_4.setText("删除");
		
		
		
		Composite composite_24 = new Composite(sashForm_8, SWT.NONE);
		composite_24.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_dept = new Table(composite_24, SWT.BORDER | SWT.FULL_SELECTION);
		table_dept.setHeaderVisible(true);
		table_dept.setLinesVisible(true);
		
		TableColumn tableColumn_8 = new TableColumn(table_dept, SWT.NONE);
		tableColumn_8.setWidth(199);
		tableColumn_8.setText("系别名称");
		sashForm_8.setWeights(new int[] {41, 644});
		
		Composite composite_20 = new Composite(sashForm_7, SWT.NONE);
		composite_20.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_9 = new SashForm(composite_20, SWT.VERTICAL);
		
		Composite composite_25 = new Composite(sashForm_9, SWT.NONE);
		composite_25.setLayout(new GridLayout(4, false));
		
		Label label_19 = new Label(composite_25, SWT.NONE);
		label_19.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_19.setText("专业名称：");
		
		text_major = new Text(composite_25, SWT.BORDER);
		text_major.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button button_addMajor = new Button(composite_25, SWT.NONE);
		button_addMajor.setText("添加");
		
		Button button_5 = new Button(composite_25, SWT.NONE);
		button_5.setText("删除");
		
		Composite composite_26 = new Composite(sashForm_9, SWT.NONE);
		composite_26.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_major = new Table(composite_26, SWT.BORDER | SWT.FULL_SELECTION);
		table_major.setHeaderVisible(true);
		table_major.setLinesVisible(true);
		
		TableColumn tableColumn_4 = new TableColumn(table_major, SWT.NONE);
		tableColumn_4.setWidth(100);
		tableColumn_4.setText("所属系别");
		
		TableColumn tableColumn_9 = new TableColumn(table_major, SWT.NONE);
		tableColumn_9.setWidth(215);
		tableColumn_9.setText("专业名称");
		sashForm_9.setWeights(new int[] {41, 644});
		
		Composite composite_21 = new Composite(sashForm_7, SWT.NONE);
		composite_21.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_10 = new SashForm(composite_21, SWT.VERTICAL);
		
		Composite composite_27 = new Composite(sashForm_10, SWT.NONE);
		composite_27.setLayout(new GridLayout(4, false));
		
		Label label_21 = new Label(composite_27, SWT.NONE);
		label_21.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_21.setText("课程名称：");
		
		text_course = new Text(composite_27, SWT.BORDER);
		text_course.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button button_addCourse = new Button(composite_27, SWT.NONE);
		button_addCourse.setText("添加");
		
		Button button_6 = new Button(composite_27, SWT.NONE);
		button_6.setText("删除");
		
		Composite composite_28 = new Composite(sashForm_10, SWT.NONE);
		composite_28.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_course = new Table(composite_28, SWT.BORDER | SWT.FULL_SELECTION);
		table_course.setHeaderVisible(true);
		table_course.setLinesVisible(true);
		
		TableColumn tableColumn_5 = new TableColumn(table_course, SWT.NONE);
		tableColumn_5.setWidth(100);
		tableColumn_5.setText("所属专业");
		
		TableColumn tblclmnNewColumn_3 = new TableColumn(table_course, SWT.NONE);
		tblclmnNewColumn_3.setWidth(225);
		tblclmnNewColumn_3.setText("课程名称");
		sashForm_10.setWeights(new int[] {41, 644});
		
		Composite composite_22 = new Composite(sashForm_7, SWT.NONE);
		composite_22.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_11 = new SashForm(composite_22, SWT.VERTICAL);
		
		Composite composite_29 = new Composite(sashForm_11, SWT.NONE);
		composite_29.setLayout(new GridLayout(4, false));
		
		Label label_23 = new Label(composite_29, SWT.NONE);
		label_23.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_23.setText("班级名称：");
		
		text_class = new Text(composite_29, SWT.BORDER);
		text_class.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button button_addClass = new Button(composite_29, SWT.NONE);
		button_addClass.setText("添加");
		
		Button button_7 = new Button(composite_29, SWT.NONE);
		button_7.setText("删除");
		
		Composite composite_30 = new Composite(sashForm_11, SWT.NONE);
		composite_30.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_class = new Table(composite_30, SWT.BORDER | SWT.FULL_SELECTION);
		table_class.setHeaderVisible(true);
		table_class.setLinesVisible(true);
		
		TableColumn tableColumn_6 = new TableColumn(table_class, SWT.NONE);
		tableColumn_6.setWidth(100);
		tableColumn_6.setText("所属专业");
		
		TableColumn tblclmnNewColumn_1 = new TableColumn(table_class, SWT.NONE);
		tblclmnNewColumn_1.setWidth(248);
		tblclmnNewColumn_1.setText("班级名称");
		sashForm_11.setWeights(new int[] {41, 644});
		sashForm_7.setWeights(new int[] {1, 1, 1, 1});
		
		TabItem tabItem_messageboard = new TabItem(tabFolder, SWT.NONE);
		tabItem_messageboard.setText("留言板");
		
		Composite composite_7 = new Composite(tabFolder, SWT.NONE);
		tabItem_messageboard.setControl(composite_7);
		composite_7.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		SashForm sashForm_2 = new SashForm(composite_7, SWT.VERTICAL);
		
		Composite composite_10 = new Composite(sashForm_2, SWT.NONE);
		composite_10.setLayout(new GridLayout(8, false));
		
		Label label_message = new Label(composite_10, SWT.NONE);
		label_message.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_message.setText("留言内容：");
		new Label(composite_10, SWT.NONE);
		
		text_message = new Text(composite_10, SWT.BORDER);
		GridData gd_text_message = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_text_message.widthHint = 607;
		text_message.setLayoutData(gd_text_message);
		
		Label label = new Label(composite_10, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("留言给：");
		
		Combo combo = new Combo(composite_10, SWT.NONE);
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button button_addMessage = new Button(composite_10, SWT.NONE);
		button_addMessage.setText("提交留言");
		
		Button button_refreshMessage = new Button(composite_10, SWT.NONE);
		button_refreshMessage.setText("刷新留言");
		new Label(composite_10, SWT.NONE);
		if ("管理员".equals(userInfo.get("roleinfo"))){
			Button button_deleteMessage = new Button(composite_10, SWT.NONE);
			button_deleteMessage.setText("删除留言");
			bandingButton_deleteMessageEvent(button_deleteMessage);
			
		}
		setLiuyanTable(combo);
		// 刷新留言板事件
		button_refreshMessage.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setMessage();
			}
		});
		
		
		Composite composite_11 = new Composite(sashForm_2, SWT.NONE);
		composite_11.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		table_message = new Table(composite_11, SWT.BORDER | SWT.FULL_SELECTION);
		table_message.setToolTipText("");
		table_message.setHeaderVisible(true);
		table_message.setLinesVisible(true);
		
		TableColumn tableColumn4 = new TableColumn(table_message, SWT.NONE);
		tableColumn4.setWidth(0);
		
		TableColumn tableColumn = new TableColumn(table_message, SWT.NONE);
		tableColumn.setWidth(76);
		tableColumn.setText("姓名");
		
		TableColumn tableColumn_2 = new TableColumn(table_message, SWT.NONE);
		tableColumn_2.setWidth(115);
		tableColumn_2.setText("时间");
		
		TableColumn tableColumn_24 = new TableColumn(table_message, SWT.NONE);
		tableColumn_24.setWidth(100);
		tableColumn_24.setText("留言给谁");
		
		TableColumn tableColumn_3 = new TableColumn(table_message, SWT.NONE);
		tableColumn_3.setWidth(1023);
		tableColumn_3.setText("内容");
		sashForm_2.setWeights(new int[] {36, 660});
		sashForm.setWeights(new int[] {228, 1057});
		
		// 获取系别
		setDeptTable();
		
		// 获取班级
		setClassTable();
		
		// 获取课程
		setCourseTable();
		
		// 获取专业
		setMajorTable();
		
		// 学生获取作业
		setStudentFiles();
		
		// 学生获取已下载作业
		setStudentDownload();
		
		// 学生获取已提交作业
		setStudentSubmit();
		
		// 教师获取作业
		setTeacherFiles();
		
		// 获取留言信息
		setMessage();
		//删除系别
		button_4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_dept.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请选择要删除的系别!");
					mb.open();
					return;
				}
				String param_value = table_dept.getItem(selectionIndex).getText(0);
				
				inputObject = new InputObject();
				inputObject.setMethod("deleteDept");
				inputObject.addParams("param_value", param_value);
				OutputObject execute = RequestService.execute(inputObject);
				if(Integer.parseInt(execute.getReturnCode())>0){
					setDeptTable();
					mb.setMessage("删除成功!");
					mb.open();
				}else{
					mb.setMessage(execute.getReturnMessage());
					mb.open();
				}
			}
		});
		//删除专业
		button_5.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_major.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请选择要删除的专业!");
					mb.open();
					return;
				}
				String param_value = table_major.getItem(selectionIndex).getText(1);
				inputObject = new InputObject();
				inputObject.setMethod("deleteMCC");
				inputObject.addParams("param_value", param_value);
				OutputObject execute = RequestService.execute(inputObject);
				if(Integer.parseInt(execute.getReturnCode())>0){
					setMajorTable();
					mb.setMessage("删除成功!");
					mb.open();
				}else{
					mb.setMessage("该专业存在课程，请先删除相关课程");
					mb.open();
				}
			}
		});
		//删除课程
		button_6.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_course.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请选择要删除的课程!");
					mb.open();
					return;
				}
				String param_value = table_course.getItem(selectionIndex).getText(1);
				inputObject = new InputObject();
				inputObject.setMethod("deleteMCC");
				inputObject.addParams("param_value", param_value);
				OutputObject execute = RequestService.execute(inputObject);
				if(Integer.parseInt(execute.getReturnCode())>0){
					setCourseTable();
					mb.setMessage("删除成功!");
					mb.open();
				}else{
					mb.setMessage("该课程存在班级，请先删除相关班级");
					mb.open();
				}
			}
		});
		//删除班级
		button_7.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_class.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请选择要删除的班级!");
					mb.open();
					return;
				}
				String param_value = table_class.getItem(selectionIndex).getText(1);
				inputObject = new InputObject();
				inputObject.setMethod("deleteMCC");
				inputObject.addParams("param_value", param_value);
				OutputObject execute = RequestService.execute(inputObject);
				System.out.println("要删除的班级"+execute);
				if(Integer.parseInt(execute.getReturnCode())>0){
					setClassTable();
					mb.setMessage("删除成功!");
					mb.open();
				}else{
					mb.setMessage("删除失败!");
					mb.open();
				}
			}
		});
		
		// 学生刷新作业列表事件
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setStudentFiles();
				MessageBox mb=new MessageBox(shell);
				mb.setMessage("刷新成功");
				mb.open();
			}
		});
		
		// 添加班级按钮事件
		button_addClass.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_major.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择专业");
					mb.open();
					return;
				}
				String text = text_class.getText();
				if (isNULL(text)) {
					mb.setMessage("请先输入班级");
					mb.open();
					return;
				}
				String major = table_major.getItem(selectionIndex).getText(1);
				inputObject = new InputObject();
				inputObject.setMethod("addCommon");
				inputObject.addParams("code", "param_class");
				inputObject.addParams("name", major);
				inputObject.addParams("value", text);
				inputObject.addParams("desc", "");
				inputObject.addParams("type", "class");
				OutputObject execute = RequestService.execute(inputObject);
				if ("0".equals(execute.getReturnCode())) {
					mb.setMessage("添加成功");
					TableItem tableItem = new TableItem(table_class, SWT.NONE);
					tableItem.setText(new String[]{major, text});
					combo_class_teacher.add(text);
				} else {
					mb.setMessage("添加失败");
				}
				mb.open();
			}
		});
		
		// 删除作业事件
		button_deleteAssign.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = uploadFileTable.getSelectionIndex();
				if (selectionIndex < 0) {
					return;
				}
				String text = uploadFileTable.getItem(selectionIndex).getText(0);
				inputObject = new InputObject();
				inputObject.addParams("fileId", text);
				inputObject.setMethod("deleteFile");
				OutputObject execute = RequestService.execute(inputObject);
				if ("0".equals(execute.getReturnCode())) {
					uploadFileTable.remove(selectionIndex);
					mb.setMessage("删除成功");
				} else {
					mb.setMessage("删除失败");
				}
				mb.open();
			}
		});
		
		// 添加系别事件
		button_addDept.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String text = text_dept.getText();
				if (isNULL(text)) {
					mb.setMessage("请先填写系别名称");
					mb.open();
					return;
				}
				inputObject = new InputObject();
				inputObject.setMethod("addCommon");
				inputObject.addParams("code", "param_dept");
				inputObject.addParams("name", "");
				inputObject.addParams("value", text);
				inputObject.addParams("desc", "");
				inputObject.addParams("type", "dept");
				OutputObject execute = RequestService.execute(inputObject);
				if ("0".equals(execute.getReturnCode())) {
					mb.setMessage("添加成功");
					TableItem tableItem = new TableItem(table_dept, SWT.NONE);
					tableItem.setText(new String[]{text});
				} else {
					mb.setMessage("添加失败");
				}
				mb.open();
			}
		});
		
		// 添加专业
		button_addMajor.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_dept.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择系别");
					mb.open();
					return;
				}
				String text = text_major.getText();
				if (isNULL(text)) {
					mb.setMessage("请先输入专业名称");
					mb.open();
					return;
				}
				String dept = table_dept.getItem(selectionIndex).getText();
				inputObject = new InputObject();
				inputObject.setMethod("addCommon");
				inputObject.addParams("code", "param_major");
				inputObject.addParams("name", dept);
				inputObject.addParams("value", text);
				inputObject.addParams("desc", "");
				inputObject.addParams("type", "major");
				OutputObject execute = RequestService.execute(inputObject);
				if ("0".equals(execute.getReturnCode())) {
					mb.setMessage("添加成功");
					TableItem tableItem = new TableItem(table_major, SWT.NONE);
					tableItem.setText(new String[]{dept, text});
				} else {
					mb.setMessage("添加失败");
				}
				mb.open();
			}
		});
		
		// 添加课程按钮事件
		button_addCourse.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_major.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择专业");
					mb.open();
					return;
				}
				String text = text_course.getText();
				if (isNULL(text)) {
					mb.setMessage("请先填写课程名称");
					mb.open();
					return;
				}
				String major = table_major.getItem(selectionIndex).getText(1);
				inputObject = new InputObject();
				inputObject.setMethod("addCommon");
				inputObject.addParams("code", "param_course");
				inputObject.addParams("name", major);
				inputObject.addParams("value", text);
				inputObject.addParams("desc", "");
				inputObject.addParams("type", "course");
				OutputObject execute = RequestService.execute(inputObject);
				if ("0".equals(execute.getReturnCode())) {
					mb.setMessage("添加成功");
					TableItem tableItem = new TableItem(table_course, SWT.NONE);
					tableItem.setText(new String[]{major, text});
					combo_course_teacher.add(text);
				} else {
					mb.setMessage("添加失败");
				}
				mb.open();
			}
		});
		
		// 获取学生提交的作业，可根据班级和课程条件查询
		button_querySubmit.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex1 = combo_class_teacher.getSelectionIndex();
				int selectionIndex2 = combo_course_teacher.getSelectionIndex();
				inputObject = new InputObject();
				if (selectionIndex1 >= 0) {
					inputObject.addParams("clazz", combo_class_teacher.getItem(selectionIndex1));
				}
				if (selectionIndex2 >= 0) {
					inputObject.addParams("course", combo_class_teacher.getItem(selectionIndex2));
				}
				inputObject.addParams("state", "已提交");//TODO 这里设置字段信息可以查看多状态的作业
				inputObject.setMethod("getFiles");
				outputObject = RequestService.execute(inputObject);
				List<Map<String, Object>> beans = outputObject.getBeans();
				if (beans.size() <= 0) {
					return;
				}
				table_checkable.removeAll();
				for (Map<String, Object> map : beans) {
					System.out.println(map.toString());
					TableItem item = new TableItem(table_checkable, SWT.NONE);
					item.setText(new String[] {(String) map.get("fileid"),(String) map.get("username"), (String) map.get("filename"), (String) map.get("uploaddate"), (String) map.get("state"),(String) map.get("score"),(String) map.get("course")});
				}
			}
		});
		
		// 上传文件事件
		button_upload.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex1 = combo_class_teacher.getSelectionIndex();
				int selectionIndex2 = combo_course_teacher.getSelectionIndex();
				if (selectionIndex1 < 0 || selectionIndex2 < 0) {
					mb.setMessage("请先选择班级和课程！");
					mb.open();
					return;
				}
				inputObject = new InputObject();
				inputObject.addParams("course", combo_course_teacher.getItem(selectionIndex2));
				inputObject.addParams("clazz", combo_class_teacher.getItem(selectionIndex1));
				inputObject.addParams("state", "使用中");
				AddAssignUI window = new AddAssignUI();
				window.setInputObject(inputObject);
				window.open();
				if (param.get("fileId") != null) {
					TableItem tableItem = new TableItem(uploadFileTable, SWT.NONE);
					tableItem.setText(new String[]{
							(String)param.get("fileId"), 
							(String)param.get("fileName"), 
							(String)param.get("uploadDate"),
							(String)param.get("validDate")
							});
				}
				
			}
		});
		
		// 提交留言事件
		button_addMessage.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				Date date = new Date();
				SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String user = (String) userInfo.get("username");
				String msgContent = text_message.getText();
				if(msgContent.trim().equals("")){
					mb.setMessage("请输入留言的内容");
					mb.open();
					return;
				}
				String msgTime = simpleDateFormat.format(date);
				inputObject = new InputObject();
				inputObject.setMethod("addMessage");
				inputObject.addParams("msgContent", msgContent);
				inputObject.addParams("msgSender", user);
				inputObject.addParams("msgTime", msgTime);
				inputObject.addParams("msgTime", msgTime);
				String toperson = combo.getText();
				String toperson1=toperson;
				if(toperson.indexOf("-")>=0){
					toperson=toperson.substring(0, toperson.indexOf("-"));
					toperson1=toperson1.substring(toperson1.indexOf("-")+1);
				}
				
				inputObject.addParams("toperson", toperson);
				outputObject = RequestService.execute(inputObject);
				if ("0".equals(outputObject.getReturnCode())) {
					TableItem tableItem= new TableItem(table_message, SWT.NONE);
					tableItem.setText(new String[]{outputObject.getReturnMessage(),user, msgTime,toperson1, msgContent});
					mb.setMessage("留言成功");
				} else {
					mb.setMessage("留言失败");
				}
				mb.open();
			}
		});
		
		// 提交作业事件
		button_submit.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				FileDialog fd = new FileDialog(shell);
				if(fd.open()==null){
					return;
				};
				String className = (String) MainUI.getUser().get("clazz");
				String userName = (String) MainUI.getUser().get("username");
				String filePath = fd.getFilterPath()+ "\\" + fd.getFileName();
				String newFileName = className + "_" + userName + "_" + fd.getFileName();
				String submitTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
				
				System.out.println(fd.getFileName());
				
				inputObject = new InputObject();
				if (filePath != null && !"".equals(filePath)) {
					File file = new File(filePath);
					inputObject.addParams("clazz", (String) MainUI.getUser().get("clazz"));
					inputObject.setMethod("uploadFile1");
					inputObject.addParams("newFileName", newFileName);
					inputObject.addParams("uploadPerson", userName);
					inputObject.addParams("file", file);
					inputObject.addParams("state", "已提交");
					OutputObject outputObject = RequestService.execute(inputObject);
					if ("0".equals(outputObject.getReturnCode())) {
						inputObject.addParams("userName", userInfo.get("username"));
						inputObject.addParams("fileName", fd.getFileName());
						inputObject.addParams("downloadTime", submitTime);
						inputObject.addParams("state", "已提交");
						inputObject.setMethod("addLog");
						outputObject = RequestService.execute(inputObject);
						if ("0".equals(outputObject.getReturnCode())) {
							TableItem tableItem= new TableItem(table_submitted, SWT.NONE);
							tableItem.setText(new String[]{fd.getFileName(), submitTime,"已提交"});
						}
						inputObject.setMethod("");
						mb.setMessage("提交作业成功");
					} else {
						mb.setMessage("提交作业失败！"+outputObject.getReturnMessage());
					}
					mb.open();
				}
			}
		});
		
		// 下载作业按钮事件	
		button_download.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_usable.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请先选择作业");
					mb.open();
					return;
				}
				String fileName = table_usable.getItem(selectionIndex).getText(0);
				inputObject = new InputObject();
				inputObject.addParams("fileName", fileName);
				inputObject.setMethod("downloadFile");
				outputObject = RequestService.execute(inputObject);
				if (outputObject.getBean().get("file") != null) {
					FileDialog fd = new FileDialog(shell, SWT.SAVE);
					fd.setFileName((String) outputObject.getBean().get("fileName"));
					if(fd.open()==null){
						return;
					};
					
					String filePath = fd.getFilterPath()+ "\\" + fd.getFileName();
					FileOutputStream fos = null;
					FileInputStream fis = null;
					try {
						File file = (File) outputObject.getBean().get("file");
						fis = new FileInputStream(file);
						fos = new FileOutputStream(filePath);
						byte[] b = new byte[1024];
						while (fis.read(b) != -1) {
							fos.write(b);
							fos.flush();
						}
						String downloadTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
						inputObject = new InputObject();
						inputObject.addParams("userName", userInfo.get("username"));
						inputObject.addParams("fileName", fd.getFileName());
						inputObject.addParams("state", "已下载");
						inputObject.addParams("downloadTime", downloadTime);
						inputObject.setMethod("addLog");
						outputObject = RequestService.execute(inputObject);
						if ("0".equals(outputObject.getReturnCode())) {
							TableItem tableItem= new TableItem(table_downloaded, SWT.NONE);
							tableItem.setText(new String[]{fileName, downloadTime});
							
						}
						mb.setMessage("下载成功！");
						mb.open();
					} catch (FileNotFoundException e1) {
						e1.printStackTrace();
					} catch (IOException e1) {
						e1.printStackTrace();
					} finally {
						try {
							if (fos != null) {
								fos.close();
							}
						} catch (IOException e1) {
							e1.printStackTrace();
						}
					}
					
				} else {
					mb.setMessage("获取文件失败");
					mb.open();
				}
			}
		});
		// TODO:权限判断
				if ("学生".equals(userInfo.get("roleinfo"))) {
					tabItem.dispose();
					tabItem_admin.dispose();
				} else if ("教师".equals(userInfo.get("roleinfo"))) {
					tabItem_student.dispose();
					tabItem_admin.dispose();
				} else if ("管理员".equals(userInfo.get("roleinfo"))) {
					//Button button_deleteMessage = new Button(composite_10, SWT.NONE);
					//button_deleteMessage.setText("删除留言");
					
					
					tabItem_student.dispose();
					tabItem.dispose();
				}
	}
	/**
	 * 绑定删除留言事件
	 * @param button_deleteMessage
	 */
	private void bandingButton_deleteMessageEvent(Button button_deleteMessage) {
		button_deleteMessage.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				int selectionIndex = table_message.getSelectionIndex();
				if (selectionIndex < 0) {
					mb.setMessage("请选择要删除的留言!");
					mb.open();
					return;
				}
				inputObject = new InputObject();
				inputObject.setMethod("deleteMessage");
				inputObject.addParams("msgid", table_message.getItem(selectionIndex).getText(0));
				outputObject = RequestService.execute(inputObject);
				if(Integer.parseInt(outputObject.getReturnCode())>0){//删除的条数
					//刷新留言板
					setMessage();
				}else{
					mb.setMessage("删除失败!");
					mb.open();
				}
		
			}
		});
	}

	private void setDeptTable() {
		inputObject = new InputObject();
		inputObject.setMethod("getCommon");
		inputObject.addParams("type", "dept");
		outputObject = RequestService.execute(inputObject);
		if (outputObject.getBeans() != null && outputObject.getBeans().size() > 0) {
			List<Map<String, Object>> list = outputObject.getBeans();
			table_dept.removeAll();
			for (Map<String, Object> map : list) {
				TableItem item = new TableItem(table_dept, SWT.NONE);
				item.setText((String) map.get("param_value"));
			}
		}
	}

	private void setClassTable() {
		inputObject = new InputObject();
		inputObject.setMethod("getCommon");
		inputObject.addParams("type", "class");
		outputObject = RequestService.execute(inputObject);
		table_class.removeAll();
		if (outputObject.getBeans().size() > 0) {
			List<Map<String, Object>> list = outputObject.getBeans();
			for (Map<String, Object> map : list) {
				TableItem item = new TableItem(table_class, SWT.NONE);
				item.setText(new String[]{(String) map.get("param_name"), (String) map.get("param_value")});
				combo_class_teacher.add((String) map.get("param_value"));
			}
		}
	}

	private void setCourseTable() {
		inputObject = new InputObject();
		inputObject.setMethod("getCommon");
		inputObject.addParams("type", "course");
		outputObject = RequestService.execute(inputObject);
		table_course.removeAll();
		if (outputObject.getBeans().size() > 0) {
			List<Map<String, Object>> list = outputObject.getBeans();
			for (Map<String, Object> map : list) {
				TableItem item = new TableItem(table_course, SWT.NONE);
				item.setText(new String[]{(String) map.get("param_name"), (String) map.get("param_value")});
				combo_course_teacher.add((String) map.get("param_value"));
			}
		}
	}

	private void setMajorTable() {
		inputObject = new InputObject();
		inputObject.setMethod("getCommon");
		inputObject.addParams("type", "major");
		outputObject = RequestService.execute(inputObject);
		table_major.removeAll();
		if (outputObject.getBeans().size() > 0) {
			List<Map<String, Object>> list = outputObject.getBeans();
			for (Map<String, Object> map : list) {
				TableItem item = new TableItem(table_major, SWT.NONE);
				item.setText(new String[]{(String) map.get("param_name"), (String) map.get("param_value")});
			}
		}
	}
	//加载已下载作业
	private void setStudentFiles() {
		inputObject = new InputObject();
		inputObject.setMethod("getFiles");
		inputObject.addParams("state", "使用中");
		inputObject.addParams("clazz", userInfo.get("clazz"));
		outputObject = RequestService.execute(inputObject);
		table_usable.removeAll();
		if (outputObject.getBeans().size() > 0) {
			List<Map<String, Object>> beans = outputObject.getBeans();
			table_usable.removeAll();
			for (Map<String, Object> map : beans) {
				TableItem item = new TableItem(table_usable, SWT.NONE);
				item.setText(new String[]{(String) map.get("filename"), (String) map.get("validdate"), (String) map.get("course")});
			}
		}
	}
	
	private void setTeacherFiles() {
		inputObject = new InputObject();
		inputObject.setMethod("getFiles");
		inputObject.addParams("uploadPerson", param.get("name"));
		inputObject.addParams("state", "使用中");
		outputObject = RequestService.execute(inputObject);
		uploadFileTable.removeAll();
		if (outputObject.getBeans().size() > 0) {
			List<Map<String, Object>> beans = outputObject.getBeans();
			for (Map<String, Object> map : beans) {
				TableItem item = new TableItem(uploadFileTable, SWT.NONE);
				item.setText(new String[]{(String) map.get("fileid"), (String) map.get("filename"), (String) map.get("uploaddate"), (String) map.get("validdate")});
			}
		}
	}
	
	private void setStudentDownload() {
		inputObject = new InputObject();
		inputObject.setMethod("getLog");
		inputObject.addParams("userName", userInfo.get("username"));
		inputObject.addParams("state", "已下载,已提交");
		List<Map<String, Object>> beans = RequestService.execute(inputObject).getBeans();
		table_downloaded.removeAll();
		for (Map<String, Object> map : beans) {
			TableItem tableItem = new TableItem(table_downloaded, SWT.NONE);
			tableItem.setText(new String[]{(String) map.get("filename"), (String) map.get("downloadtime")});
		}
	}
	
	private void setStudentSubmit() {
		//TODO 学生提交作业表格刷新
		System.out.println("学生提交作业表格刷新");
		inputObject = new InputObject();
		inputObject.setMethod("getFiles");
		inputObject.addParams("uploadPerson", userInfo.get("username"));
		inputObject.addParams("state", "已提交,已批改");
		List<Map<String, Object>> beans = RequestService.execute(inputObject).getBeans();
		table_submitted.removeAll();
		for (Map<String, Object> map : beans) {
			System.out.println("学生提交作业数据"+map.toString());
			TableItem tableItem = new TableItem(table_submitted, SWT.NONE);
			tableItem.setText(new String[]{(String) map.get("filename"), (String) map.get("uploaddate"),(String) map.get("state"), (String) map.get("score")});
		}
	}
	
	private void setMessage() {
		System.out.println("加载留言列表");
		inputObject = new InputObject();
		inputObject.setMethod("getMessages");
		inputObject.addParams("toperson", userInfo.get("userid"));
		inputObject.addParams("msgsender", userInfo.get("username"));
		System.out.println(userInfo.toString());
		List<Map<String, Object>> messages = RequestService.execute(inputObject).getBeans();
		if (messages.size() < 0) {
			return;
		}
		table_message.removeAll();
		for (Map<String, Object> map : messages) {
			TableItem tableItem = new TableItem(table_message, SWT.NONE);
			if( map.get("username")!=null){
				tableItem.setText(new String[]{(String) map.get("msgid"),(String) map.get("msgsender"), (String) map.get("msgtime"),(String) map.get("username"), (String) map.get("msgcontent")});
			}else{
				tableItem.setText(new String[]{(String) map.get("msgid"),(String) map.get("msgsender"), (String) map.get("msgtime"),(String) map.get("toperson"), (String) map.get("msgcontent")});
			}
		}
	}
	
	private boolean isNULL(Object o) {
		return o==null || "".equals(o);
	}
	
	private void setLiuyanTable(Combo combo) {
		inputObject = new InputObject();
		inputObject.setMethod("getPerson");
		outputObject = RequestService.execute(inputObject);
		List<Map<String, Object>> list = outputObject.getBeans();
		combo.removeAll();
		if (list.size() > 0) {
			combo.add("所有人");
			for (Map<String, Object> map : list) {
				combo.add((String) map.get("userid")+"-"+(String) map.get("username"));
			}
			combo.select(0);
		}
	}

}